n, m = map(int, input().split())
a = [0] * n
for i in range(n):
    a[i] = int(input())
    if a[i] > n:
        a[i] = n

cnt = [0] * (n + 1)
se = set(range(n + 1))

ans = 1000000

for i in range(m):
    if cnt[a[i]] == 0:
        se.remove(a[i])
    cnt[a[i]] += 1

ans = min(ans, min(se))

for i in range(m, n):
    if cnt[a[i]] == 0:
        se.remove(a[i])
    if cnt[a[i - m]] == 1:
        se.add(a[i - m])
    ans = min(ans, min(se))

print(ans)